package com.pdstudio.carrecom.app;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.ImageView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.pdstudio.carrecom.api.HttpExecuteJson;
import com.pdstudio.carrecom.api.ServiceHelper;
import com.pdstudio.carrecom.bean.InitPage;
import com.pdstudio.carrecom.bean.ResultInfo;
import com.pdstudio.carrecom.common.BaseActivity;
import com.pdstudio.carrecom.logger.Logger;
import com.pdstudio.carrecom.tools.JsonUtil;
import com.pdstudio.carrecom.ui.activity.GuideActivity;
import com.pdstudio.carrecom.R;

/**
 * 应用程序启动类：显示欢迎界面并跳转到主界面
 * 
 * @author liukai
 */
public class AppStart extends BaseActivity {
	AppContext mApp;

    public static final String TAG="AppStart";

	private Timer mTimer = null;
	private TimerTask mTimerTask = null;
	private long delay = 5000;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		final View view = View.inflate(this, R.layout.app_start, null);

		setContentView(view);
		mContext = this;
        //getAdImage();

		if (AppContext.debug) {
			// UIHelper.ToastMessage(this, "您现在进入的是调试版本!");
		}

		startTimer();
		
	}

	/**
	 * 跳转到主界面
	 */
	private void redirectTo() {

		DisplayMetrics dm = new DisplayMetrics();
		this.getWindowManager().getDefaultDisplay().getMetrics(dm);
		AppContext.getInstance()._screenWidth = dm.widthPixels;
		AppContext.getInstance()._screenHeight = dm.heightPixels;

		Intent intent = new Intent(mContext, GuideActivity.class);
		startActivity(intent);
		finish();
	}

	/**
	 * 
	 * 方法: startTimer <br>
	 * 描述: 打开timer <br>
	 * 作者: ws <br>
	 * 时间: 2015-5-21 上午1:09:23
	 */
	private void startTimer() {
		if (mTimer == null) {
			mTimer = new Timer();
		}

		if (mTimerTask == null) {
			mTimerTask = new TimerTask() {
				@Override
				public void run() {
					Intent intent = new Intent(AppStart.this,
							GuideActivity.class);
					startActivity(intent);
					stopTimer();
					finish();
				}
			};
		}

		if (mTimer != null && mTimerTask != null)
			mTimer.schedule(mTimerTask, delay);
	}

	/**
	 * 关闭timer
	 */
	private void stopTimer() {

		if (mTimer != null) {
			mTimer.cancel();
			mTimer = null;
		}

		if (mTimerTask != null) {
			mTimerTask.cancel();
			mTimerTask = null;
		}
	}
}
